package com.ruoyi.obtain.service.impl;

import java.util.ArrayList;
import java.util.List;

import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.obtain.domain.EduTeacher;
import com.ruoyi.system.mapper.SysUserRoleMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.obtain.mapper.EduHelpMapper;
import com.ruoyi.obtain.domain.EduHelp;
import com.ruoyi.obtain.service.IEduHelpService;

/**
 * 就业帮扶Service业务层处理
 * 
 * @author ruoyi
 * @date 2022-11-09
 */
@Service
public class EduHelpServiceImpl implements IEduHelpService 
{
    @Autowired
    private EduHelpMapper eduHelpMapper;

    @Autowired
    private SysUserRoleMapper sysUserRoleMapper;
    /**
     * 查询就业帮扶
     * 
     * @param id 就业帮扶主键
     * @return 就业帮扶
     */
    @Override
    public EduHelp selectEduHelpById(Long id)
    {
        return eduHelpMapper.selectEduHelpById(id);
    }

    /**
     * 查询就业帮扶列表
     * 
     * @param eduHelp 就业帮扶
     * @return 就业帮扶
     */
    @Override
    public List<EduHelp> selectEduHelpList(EduHelp eduHelp)
    {
        Long userId = SecurityUtils.getUserId();
        Long roleId = sysUserRoleMapper.selectRoleByUserId(userId);

        if(roleId == 4){
            return eduHelpMapper.selectTeacherByUserId(userId);
        }else{
            return eduHelpMapper.selectEduHelpList(eduHelp);
        }
        //eduHelpMapper.selectTeacherByUserId()

    }

    /**
     * 新增就业帮扶
     * 
     * @param eduHelp 就业帮扶
     * @return 结果
     */
    @Override
    public int insertEduHelp(EduHelp eduHelp)
    {
        eduHelp.setHelpStates(1);
        return eduHelpMapper.insertEduHelp(eduHelp);
    }

    /**
     * 修改就业帮扶
     * 
     * @param eduHelp 就业帮扶
     * @return 结果
     */
    @Override
    public int updateEduHelp(EduHelp eduHelp)
    {
        return eduHelpMapper.updateEduHelp(eduHelp);
    }

    /**
     * 批量删除就业帮扶
     * 
     * @param ids 需要删除的就业帮扶主键
     * @return 结果
     */
    @Override
    public int deleteEduHelpByIds(Long[] ids)
    {
        return eduHelpMapper.deleteEduHelpByIds(ids);
    }

    /**
     * 删除就业帮扶信息
     * 
     * @param id 就业帮扶主键
     * @return 结果
     */
    @Override
    public int deleteEduHelpById(Long id)
    {
        return eduHelpMapper.deleteEduHelpById(id);
    }

    @Override
    public List<EduHelp> list(EduHelp eduHelp) {

        Long userId = SecurityUtils.getUserId();

        Long roleId = sysUserRoleMapper.selectRoleByUserId(userId);

        List<EduHelp> list= new ArrayList<>();

        if(roleId == 4){
             list = eduHelpMapper.selectTeacherByUserId(userId);
        }
        else{
            list = eduHelpMapper.selectEduHelpList(eduHelp);
        }
        //eduHelpMapper.selectTeacherByUserId()
        return list;
    }
}
